package sk.stuba.fiit.foo07.genex.gui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class ProgressCellRenderer extends JProgressBar implements
        TableCellRenderer {

    /**
     * 
     */
    private static final long serialVersionUID = -3016786372481872199L;

    private static Color[] colors = { Color.WHITE, Color.GREEN, Color.YELLOW,
            Color.BLUE, Color.MAGENTA, Color.RED };

    public ProgressCellRenderer() {
        super(0, 5);
        setIntegerValue(1);
        setStringPainted(true);
        setBackground(new Color(255, 255, 240));
        setBorderPainted(false);
    }

    public void setIntegerValue(Integer value) {
        super.setValue(value);

        if (value == -1)
            setString("KAT");
        else {
            setString(value.toString());
            setForeground(colors[value]);
        }
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        Integer val = (Integer) value;
        setIntegerValue(val);

        return this;
    }
}
